package org.example.douban;

import org.example.douban.parser.BookAdapter;
import org.example.douban.spider.BookInfoSpider;
import org.example.douban.spider.BookUrlsSpider;
import org.example.douban.spider.StartSpider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;

/**
 * @author wwy
 * @date 2020-11-07 11:10
 */
@SpringBootApplication
@EntityScan("org.example.framework.domain")
public class BookApplication {
    public static void main(String[] args) {
        ApplicationContext applicationContext = SpringApplication.run(BookApplication.class, args);
        BookAdapter.applicationContext = applicationContext;
        BookInfoSpider.applicationContext = applicationContext;
        BookUrlsSpider.applicationContext = applicationContext;
        StartSpider.applicationContext = applicationContext;
        //开始爬取，首先执行BookUrlsSpider,再次执行BookInfoSpider
        Environment environment = applicationContext.getEnvironment();
        String bookClassName = environment.getProperty("bookClassName");
        StartSpider startSpider = new StartSpider(bookClassName);
        //StartSpider startSpider = new StartSpider("BookInfoSpider");
    }
}
